const path = require('path')
const Timestamp = new Date().getTime()

function resolve(dir) {
  return path.join(__dirname, dir)
}
let proxyObj = {};
proxyObj['/api'] = {
  ws: false,
  pathRewrite: {
    '^/api': ''
  },
  target: process.env.VUE_APP_BASE_API,
  changeOrigin: true, //是否跨域
  secure: true, //https请求需要配置
}
// const { defineConfig } = require('@vue/cli-service')
// module.exports = defineConfig({
//   transpileDependencies: true,
//   lintOnSave: false,
//   devServer: {
//     host: 'localhost',
//     port: 8080,
//     open: true,
//     proxy: {
//       '/api/': {
//         targer: 'http://cloudtest.3ydata.com',
//         changeOrigin: true,
//         secure: true,
//         pathRewrite:{
//           '^/api': ''
//         }
//       }
//     }
// },
// })
module.exports = {
  lintOnSave: false,
  productionSourceMap: false,
  devServer: {
    host: '0.0.0.0',
    // public: '192.168.2.117:8080',
    port: 8085,
    open: true,
    proxy: proxyObj
  },
  // svg配置
  chainWebpack(config) {
    config.module
      .rule('svg')
      .exclude
      .add(resolve('src/assets/icons'))
      .end();
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/assets/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end();
    // 打包编辑后修改js文件名
    config.output.filename = `js/[name].${Timestamp}.js`;
    config.output.chunkFilename = `js/[name].${Timestamp}.js`;
  },
  //优化
  // configureWebpack: {
  //   externals: {
  //     'vue': 'Vue',
  //     'element-ui': 'ELEMENT',
  //   }
  // },
  css: {
    extract: {
      filename: `css/[name].${Timestamp}.css`,
      chunkFilename: `css/[name].${Timestamp}.css`
    }
  }
}
